<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/element-plus/2.3.2/index.css" rel="stylesheet">
</head>

<body>

    <div id="app">

        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="date" label="日期" width="180">

            </el-table-column>
            <el-table-column prop="name" label="姓名" width="180">

                <!-- 在子组件内部使用插槽 -->
                <template #default="{row}">
                    <h1>{{row.name}}</h1>
                </template>

            </el-table-column>
            <el-table-column prop="address" label="地址"></el-table-column>
            <el-table-column label="操作">

                <!-- 在子组件内部使用作用域插槽 -->
                <!-- <template v-slot="{row}">
                    <el-button type="success" @click="onDetail(row)">详情</el-button>
                    {{row}}
                </template> -->

                <template #default="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
                    <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">Delete
                    </el-button>
                </template>

            </el-table-column>
        </el-table>



    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <!-- 一定要在引入vue3之后再引入element-plus  -->
    <script src="https://cdn.bootcdn.net/ajax/libs/element-plus/2.3.2/index.full.js"></script>
    <script>
        var app = Vue.createApp({
            data: function () {
                return {
                    tableData: [
                        {
                            date: '2016-05-03',
                            name: 'Zoom',
                            address: 'No. 189, Grove St, Los Angeles',
                        },
                        {
                            date: '2016-05-02',
                            name: 'Tom',
                            address: 'No. 189, Grove St, Los Angeles',
                        },
                        {
                            date: '2016-05-04',
                            name: 'Tom',
                            address: 'No. 189, Grove St, Los Angeles',
                        },
                        {
                            date: '2016-05-01',
                            name: 'Tom',
                            address: 'No. 189, Grove St, Los Angeles',
                        },
                    ]
                }
            },
            methods: {
                onDetail(row) {
                    console.log(row);
                },
                handleEdit(index, row) {
                    console.log('index::', index);
                    console.log('row::', row);
                },
                handleDelete(index, row) {
                    this.tableData.splice(index, 1);
                }
            },

        })
        app.use(ElementPlus)
        app.mount('#app');
    </script>
</body>

</html>